import { ElMessage } from "element-plus"
import http from "@/utils/http"
function useUpdFile() {
  const uploadImg = async (
    event: Event,
    insertImage: ({ url, desc }: { url: string; desc: string }) => void,
    files: Array<File>
  ) => {
    const formData = new FormData()
    formData.append("file", files[0])
    const res = await http.upload<string>("/file/uploadFile", formData)
    if (res.code === 1) {
      insertImage({
        url: res.data as string,
        desc: "",
      })
    } else {
      ElMessage.error("上传失败")
    }
  }
  return { uploadImg }
}
export default useUpdFile
